package com.test.daily.leetcode.y2022.m05.day0524.v05;

import java.util.PriorityQueue;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/5/24 下午 08:01
 * @version: 1.0
 */
public class Solution {
    public static int merge(int[] arr, int pre) {
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                min = Math.min(min, merge(mergeTwoElement(arr, i, j), pre + arr[i] + arr[j]));
            }
        }
        return min;
    }

    public static int[] mergeTwoElement(int[] arr, int i, int j) {
        int[] ans = new int[arr.length - 1];
        int index = 0;
        for (int k = 0; k < arr.length; k++) {
            if (k != i && k != j) {
                ans[index++] = arr[k];
            }
        }
        return ans;
    }
    public static int min2(int[] arr){
        int ans = 0;
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            pq.add(arr[i]);
        }
        while(pq.size() > 1){
            int newEle = pq.poll() + pq.poll();
            pq.add(newEle);
        }
        return pq.poll();
    }
}
